//
//  SLBaseNavController.swift
//  Sina15
//
//  Created by 盼 on 16/4/8.
//  Copyright © 2016年 pan. All rights reserved.
//

import UIKit

class SLBaseNavController: UINavigationController,UIGestureRecognizerDelegate {
    
    override func viewDidLoad() {
        
        //返回手势的解决
        
    
       navigationBar.setBackgroundImage(UIImage(named: "navbarbackimaegg"), forBarMetrics: .Default)
        self.interactivePopGestureRecognizer?.delegate = self
    }
    
    //实现代理方法解决首页使用手势页面卡顿
     func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool{
        
        if childViewControllers.count == 1 {
            
            return false
        }else{
            return true
        }
    }
    
    //重写导航控制器的push方法
    override func pushViewController(viewController: UIViewController, animated: Bool) {
        
        var backTitle = "返回"
        
        if childViewControllers.count  > 0 {
            
            if childViewControllers.count == 1 {
                //如果是第一个控制器，把第一个控制器的title是第一个控制器的title
                backTitle = childViewControllers.first?.title ?? ""
            }
            
        viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(imageName: "navigationbar_back_withtext", title: backTitle, target: self, action: "pop")
            
            //push控制器的时候隐藏底部的导航栏
            viewController.hidesBottomBarWhenPushed = true

        }
    
        super.pushViewController(viewController, animated: true)
        
        
    }
    
    @objc private func pop(){
        
        
        self.popViewControllerAnimated(true)
    }

}
